package com.tech.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.alibaba.dubbo.config.annotation.Service;
import com.tech.pojo.ItemCat;
import com.tech.pojo.ItemCatMenu;
import com.tech.service.ItemCatService;
import com.tech.service.util.CreateMenuTreeUtil;
import com.tech.utils.BeanCopierUtils;

@Service
@org.springframework.stereotype.Service("ItemCatServiceImpl")
public class ItemCatServiceImpl extends IServiceImpl<ItemCat>  implements ItemCatService {

    @Override
    public List<ItemCat> getItemCatList() {
        List<ItemCat> itemCatList = this.selectAll();
        for (ItemCat itemCat : itemCatList) {
            
        }
        return itemCatList;
    }

    @Override
    public Map<String, Object> getMenuList() {
        List<ItemCat> itemCatList = this.getItemCatList();
        List<ItemCatMenu> menuList = new ArrayList<>();
        try {
            BeanCopierUtils.copyListProperties(itemCatList, menuList,ItemCatMenu.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Map<String, Object> menuMap = CreateMenuTreeUtil.getInstance().findTree(menuList);
        return menuMap;
    }
    
    
//    public static void main(String[] args) throws Exception {
//        List<ItemCat> itemCatList = new ArrayList<>();
//        ItemCat cat = new ItemCat();
//        cat.setId(Long.parseLong("1001"));
//        cat.setParentId(Long.parseLong("101"));
//        cat.setName("test_cat");
//        itemCatList.add(cat);
//        Menu menu = new Menu();
//        org.apache.commons.beanutils.BeanUtils.copyProperties(menu,cat);
//        System.out.println(menu.getName());
//        
//        List<Menu> menuList = new ArrayList<>();
//        BeanCopierUtils.copyListProperties(itemCatList,menuList, Menu.class);
////        System.out.println(menuList);
//    }
//    

}
